<template>
  <div class="student-profile-container">
    <div class="profile-header">
      <div class="header-content">
        <h1 class="page-title">学生个人档案</h1>
        <div class="action-buttons">
          <el-button v-if="!isEditing" type="primary" icon="Edit" @click="handleEdit">编辑信息</el-button>
          <template v-else>
            <el-button type="success" icon="Check" @click="saveEdit">保存</el-button>
            <el-button type="warning" icon="Close" @click="cancelEdit">取消</el-button>
          </template>
        </div>
      </div>
    </div>

    <el-form ref="studentMangerRef" :model="form" label-width="160px" v-loading="loading">
      <div class="profile-content">
        <!-- 合并后的个人信息区域 -->
        <el-card shadow="never" class="info-card">
          <template #header>
            <div class="card-header">
              <i-ep-user class="header-icon" />
              <span>个人信息</span>
            </div>
          </template>

          <div class="info-group">
            <el-row :gutter="20">
              <!-- 照片信息放在左侧：上传组件用显示隐藏控制权限 -->
              <el-col :span="4">
                <div class="photo-section">
                  <div class="photo-item">
                    <div class="photo-label">入学照片</div>
                    <div class="photo-preview">
                      <!-- 入学照片上传：权限控制显示 -->
                      <ImageUpload
                          v-if="isEditing && fieldPermissions.studentPhoto"
                          v-model="form.studentPhoto"
                          :limit="1"
                          :file-type="['jpg', 'jpeg', 'png']"
                      />
                      <el-image
                          v-else
                          :src="getImageUrl(form.studentPhoto)"
                          class="photo-img"
                          fit="cover"
                          :preview-src-list="[getImageUrl(form.studentPhoto)]"
                          preview-teleported>
                        <template #error>
                          <div class="image-slot">
                            <i-ep-picture />
                            <div>暂无照片</div>
                          </div>
                        </template>
                      </el-image>
                    </div>
                    <div v-if="isEditing && fieldPermissions.studentPhoto" class="upload-tips">
                      请上传大小不超过5MB，格式为jpg/jpeg/png的文件
                    </div>
                  </div>
                </div>
              </el-col>

              <!-- 中间：毕业照片 -->
              <el-col :span="4">
                <div class="photo-section">
                  <div class="photo-item">
                    <div class="photo-label">毕业照片</div>
                    <div class="photo-preview">
                      <!-- 毕业照片上传：权限控制显示 -->
                      <ImageUpload
                          v-if="isEditing && fieldPermissions.studentGphoto"
                          v-model="form.studentGphoto"
                          :limit="1"
                          :file-type="['jpg', 'jpeg', 'png']"
                      />
                      <el-image
                          v-else
                          :src="getImageUrl(form.studentGphoto)"
                          class="photo-img"
                          fit="cover"
                          :preview-src-list="[getImageUrl(form.studentGphoto)]"
                          preview-teleported>
                        <template #error>
                          <div class="image-slot">
                            <i-ep-picture />
                            <div>暂无照片</div>
                          </div>
                        </template>
                      </el-image>
                    </div>
                    <div v-if="isEditing && fieldPermissions.studentGphoto" class="upload-tips">
                      请上传大小不超过5MB，格式为jpg/jpeg/png的文件
                    </div>
                  </div>
                </div>
              </el-col>

              <!-- 基本信息放在右侧：所有编辑组件加权限控制 -->
              <el-col :span="12">
                <div class="basic-info-section">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <el-form-item label="姓名：">
                        <span v-if="!isEditing">{{ form.studentName || '未填写' }}</span>
                        <el-input
                            v-else
                            v-model="form.studentName"
                            @input="getNamePy"
                            :disabled="!fieldPermissions.studentName"
                            placeholder="姓名不可修改"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="学号：">
                        <span v-if="!isEditing">{{ form.studentId || '未填写' }}</span>
                        <el-input
                            v-else
                            v-model="form.studentId"
                            :disabled="!fieldPermissions.studentId"
                            placeholder="学号不可修改"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="性别：">
                        <span v-if="!isEditing">{{ getDictLabel(sys_user_sex, form.studentSex) || '未填写' }}</span>
                        <el-select
                            v-else
                            v-model="form.studentSex"
                            style="width: 100%;"
                            :disabled="!fieldPermissions.studentSex">
                          <el-option
                              v-for="dict in sys_user_sex"
                              :key="dict.value"
                              :label="dict.label"
                              :value="dict.value">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="出生日期：">
                        <span v-if="!isEditing">{{ form.birthday ? form.birthday.substring(0, 10) : '未填写' }}</span>
                        <el-date-picker
                            v-else
                            v-model="form.birthday"
                            type="date"
                            value-format="YYYY-MM-DD"
                            style="width: 100%;"
                            :disabled="!fieldPermissions.birthday">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="民族：">
                        <span v-if="!isEditing">{{ getNationLabel(form.studentNation) || '未填写' }}</span>
                        <el-select
                            v-else
                            v-model="form.studentNation"
                            style="width: 100%;"
                            :disabled="!fieldPermissions.studentNation">
                          <el-option v-for="item in originnationlist"
                                     :key="item.id"
                                     :label="item.nadictLabel"
                                     :value="item.nadictValue">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="政治面貌：">
                        <span v-if="!isEditing">{{ getPoliticalLabel(form.studentPa) || '未填写' }}</span>
                        <el-select
                            v-else
                            v-model="form.studentPa"
                            style="width: 100%;"
                            :disabled="!fieldPermissions.studentPa">
                          <el-option v-for="item in originpaList"
                                     :key="item.id"
                                     :label="item.politicalLabel"
                                     :value="item.politicalValue">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <!-- 新增36：现役军人码 -->
                    <el-col :span="12">
                      <el-form-item label="现役军人码：" label-width="120px">
                        <span v-if="!isEditing">{{ form.studentXyjrDm || '未填写' }}</span>
                        <el-input
                            v-else
                            v-model="form.studentXyjrDm"
                            :disabled="!fieldPermissions.studentXyjrDm" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="姓名拼音：">
                        <span v-if="!isEditing">{{ form.namePy || '未填写' }}</span>
                        <el-input
                            v-else
                            v-model="form.namePy"
                            :disabled="!fieldPermissions.namePy" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="曾用名：">
                        <span v-if="!isEditing">{{ form.studentNames || '未填写' }}</span>
                        <el-input
                            v-else
                            v-model="form.studentNames"
                            :disabled="!fieldPermissions.studentNames" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="宗教信仰：">
                        <span v-if="!isEditing">{{ form.studentRe || '未填写' }}</span>
                        <el-input
                            v-else
                            v-model="form.studentRe"
                            :disabled="!fieldPermissions.studentRe" />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="form.studentPa === '03'">
                      <el-form-item label="入党时间：">
                        <span v-if="!isEditing">{{ form.studentTjp ? form.studentTjp.substring(0, 10) : '未填写'  }}</span>
                        <el-date-picker
                            v-else
                            v-model="form.studentTjp"
                            type="date"
                            value-format="YYYY-MM-DD"
                            style="width: 100%;"
                            :disabled="!fieldPermissions.studentTjp">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </div>

      <!-- 地区信息卡片：级联选择器加权限控制 -->
      <el-card shadow="never" class="info-card full-width-card">
        <template #header>
          <div class="card-header">
            <i-ep-location class="header-icon" />
            <span>地区信息</span>
          </div>
        </template>

        <div class="info-group">
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="国家地区：">
                <span v-if="!isEditing">{{ regionText || '未填写' }}</span>
                <el-cascader
                    v-else
                    v-model="selectedOptions"
                    style="width: 100%;"
                    size="large"
                    :options="options"
                    @change="handleChange"
                    :disabled="!fieldPermissions.studentRegion">
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="籍贯：">
                <span v-if="!isEditing">{{ jiguanText || '未填写' }}</span>
                <el-cascader
                    v-else
                    v-model="selectedJiguan"
                    style="width: 100%;"
                    size="large"
                    :options="options"
                    @change="handleChangeJiguan"
                    :disabled="!fieldPermissions.studentJiguan">
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="出生地：">
                <span v-if="!isEditing">{{ bireText || '未填写' }}</span>
                <el-cascader
                    v-else
                    v-model="selectedBire"
                    style="width: 100%;"
                    size="large"
                    :options="options"
                    @change="handleChangeBire"
                    :disabled="!fieldPermissions.studentBire">
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="生源地：">
                <span v-if="!isEditing">{{ streText || '未填写' }}</span>
                <el-cascader
                    v-else
                    v-model="selectedStre"
                    style="width: 100%;"
                    size="large"
                    :options="options"
                    @change="handleChangeStre"
                    :disabled="!fieldPermissions.studentStre">
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="户口所在地：">
                <span v-if="!isEditing">{{ hkText || '未填写' }}</span>
                <el-cascader
                    v-else
                    v-model="selectedHk"
                    style="width: 100%;"
                    size="large"
                    :options="options"
                    @change="handleChangeHk"
                    :disabled="!fieldPermissions.studentHk">
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="详细地址：">
                <span v-if="!isEditing">{{ form.studentHkxxdz || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentHkxxdz"
                    :disabled="!fieldPermissions.studentHkxxdz" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>

      <!-- 联系方式卡片：输入框/下拉框加权限控制 -->
      <el-card shadow="never" class="info-card full-width-card">
        <template #header>
          <div class="card-header">
            <i-ep-phone class="header-icon" />
            <span>联系方式</span>
          </div>
        </template>

        <div class="info-group">
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="本人手机号：">
                <span v-if="!isEditing">{{ form.studentSjh || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentSjh"
                    :disabled="!fieldPermissions.studentSjh" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="辅导员：">
                <span v-if="!isEditing">{{ form.studentFdy || '未填写' }}</span>
                <el-select
                    v-else
                    v-model="form.studentFdy"
                    style="width: 100%;"
                    :disabled="!fieldPermissions.studentFdy">
                  <el-option
                      v-for="item in teacherList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.name">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="辅导员电话：">
                <span v-if="!isEditing">{{ form.studentFdynum || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentFdynum"
                    :disabled="!fieldPermissions.studentFdynum" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="第一书记：">
                <span v-if="!isEditing">{{ form.studentShuji || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentShuji"
                    :disabled="!fieldPermissions.studentShuji" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="书记电话：">
                <span v-if="!isEditing">{{ form.studentSjnum || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentSjnum"
                    :disabled="!fieldPermissions.studentSjnum" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>

      <!-- 银行卡信息卡片：输入框加权限控制 -->
      <el-card shadow="never" class="info-card full-width-card">
        <template #header>
          <div class="card-header">
            <i-ep-train class="header-icon" />
            <span>银行卡信息</span>
          </div>
        </template>

        <div class="info-group">
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="银行卡号：">
                <span v-if="!isEditing">{{ form.studentYhkh || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentYhkh"
                    :disabled="!fieldPermissions.studentYhkh" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="银行卡姓名：">
                <span v-if="!isEditing">{{ form.studentYhkname || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentYhkname"
                    :disabled="!fieldPermissions.studentYhkname" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>

      <!-- 火车起始终点站信息卡片：输入框加权限控制 -->
      <el-card shadow="never" class="info-card full-width-card">
        <template #header>
          <div class="card-header">
            <i-ep-train class="header-icon" />
            <span>火车起始终点站信息</span>
          </div>
        </template>

        <div class="info-group">
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="火车起点站：">
                <span v-if="!isEditing">{{ form.studentTrains || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentTrains"
                    :disabled="!fieldPermissions.studentTrains" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="火车终点站：">
                <span v-if="!isEditing">{{ form.studentTraine || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentTraine"
                    :disabled="!fieldPermissions.studentTraine" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>

      <!-- 证件信息卡片：下拉框/输入框加权限控制 -->
      <el-card shadow="never" class="info-card full-width-card">
        <template #header>
          <div class="card-header">
            <i-ep-tickets class="header-icon" />
            <span>证件信息</span>
          </div>
        </template>

        <div class="info-group">
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="证件类型：">
                <span v-if="!isEditing">{{ getZjlxLabel(form.studentCtype) || '未填写' }}</span>
                <el-select
                    v-else
                    v-model="form.studentCtype"
                    style="width: 100%;"
                    :disabled="!fieldPermissions.studentCtype">
                  <el-option v-for="item in zjlxList"
                             :key="item.id"
                             :label="item.cardtLabel"
                             :value="item.cardtValue">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="证件号码：">
                <span v-if="!isEditing">{{ form.studentCnum || '未填写' }}</span>
                <el-input
                    v-else
                    v-model="form.studentCnum"
                    @input="getSex"
                    :disabled="!fieldPermissions.studentCnum" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>

      <!-- 教育背景卡片：所有子卡片编辑组件加权限控制 -->
      <el-card shadow="never" class="info-card full-width-card">
        <template #header>
          <div class="card-header">
            <i-ep-reading class="header-icon" />
            <span>教育背景</span>
          </div>
        </template>

        <!-- 学习信息子卡片 -->
        <el-card shadow="never" class="info-card">
          <template #header>
            <div class="card-header">
              <span>学习信息</span>
            </div>
          </template>
          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="院系：">
                  <span v-if="!isEditing">{{ getCollegeName(form.studentYx) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentYx"
                      @change="handleCollegeChange"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentYx">
                    <el-option v-for="item in yxList"
                               :key="item.collegeId"
                               :label="item.collegeName"
                               :value="item.collegeCode">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="专业：">
                  <span v-if="!isEditing">{{ getMajorName(form.studentZy) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentZy"
                      :disabled="!form.studentYx || !fieldPermissions.studentZy"
                      style="width: 100%;">
                    <el-option v-for="item in zyList"
                               :key="item.id"
                               :label="item.majorName"
                               :value="item.majorCode">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="年级：">
                  <span v-if="!isEditing">{{ form.studentNj || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentNj"
                      :disabled="!fieldPermissions.studentNj" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="班级：">
                  <span v-if="!isEditing">{{ form.studentBj || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentBj"
                      :disabled="!fieldPermissions.studentBj" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="校区：">
                  <span v-if="!isEditing">{{ getDictLabel(campus_type, form.studentXq) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentXq"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentXq">
                    <el-option
                        v-for="dict in campus_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学生类别：">
                  <span v-if="!isEditing">{{ form.studentLb || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentLb"
                      :disabled="!fieldPermissions.studentLb" />
                </el-form-item>
              </el-col>
              <!-- 研究方向 -->
              <el-col :span="8">
                <el-form-item label="研究方向：">
                  <span v-if="!isEditing">{{ form.studentYjfx || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentYjfx"
                      :disabled="!fieldPermissions.studentYjfx" />
                </el-form-item>
              </el-col>
              <!-- 研究方向码 -->
              <el-col :span="8">
                <el-form-item label="研究方向码：">
                  <span v-if="!isEditing">{{ form.studentYjfxm || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentYjfxm"
                      :disabled="!fieldPermissions.studentYjfxm" />
                </el-form-item>
              </el-col>
              <!-- 培养层次 -->
              <el-col :span="8">
                <el-form-item label="培养层次：">
                  <span v-if="!isEditing">{{ getDictLabel(culture_program_type, form.studentPycc) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentPycc"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentPycc">
                    <el-option
                        v-for="dict in culture_program_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 导师信息子卡片 -->
        <el-card shadow="never" class="info-card">
          <template #header>
            <div class="card-header">
              <span>导师信息</span>
            </div>
          </template>
          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="导师1编号：">
                  <span v-if="!isEditing">{{ form.studentDsbh || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentDsbh"
                      :disabled="!fieldPermissions.studentDsbh" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="导师2编号：">
                  <span v-if="!isEditing">{{ form.studentDs2bh || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentDs2bh"
                      :disabled="!fieldPermissions.studentDs2bh" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="导师：">
                  <span v-if="!isEditing">{{ getTeacherName(form.studentDs) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentDs"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentDs">
                    <el-option
                        v-for="item in teacherList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.teacherCode">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="导师2：">
                  <span v-if="!isEditing">{{ getTeacherName(form.studentDs2) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentDs2"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentDs2">
                    <el-option
                        v-for="item in teacherList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.teacherCode">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>






            </el-row>
          </div>
        </el-card>

        <!-- 学制与入学信息子卡片 -->
        <el-card shadow="never" class="info-card">
          <template #header>
            <div class="card-header">
              <span>学制与入学信息</span>
            </div>
          </template>
          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="学制：">
                  <span v-if="!isEditing">{{ getDictLabel(xuezhi, form.studentXz) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentXz"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentXz">
                    <el-option
                        v-for="dict in xuezhi"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="入学季节：">
                  <span v-if="!isEditing">{{ getDictLabel(semester, form.studentRxjj) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentRxjj"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentRxjj">
                    <el-option
                        v-for="dict in semester"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="入学年月：">
                  <span v-if="!isEditing">{{ form.studentRxny ? form.studentRxny.substring(0, 10) : '未填写' }}</span>
                  <el-date-picker
                      v-else
                      v-model="form.studentRxny"
                      type="month"
                      value-format="YYYY-MM"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentRxny">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="预计毕业时间：">
                  <span v-if="!isEditing">{{ form.studentYjby ? form.studentYjby.substring(0, 10) : '未填写' }}</span>
                  <el-date-picker
                      v-else
                      v-model="form.studentYjby"
                      type="date"
                      value-format="YYYY-MM-DD"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentYjby">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="实际毕业时间：">
                  <span v-if="!isEditing">{{ form.studentSjby ? form.studentSjby.substring(0, 10) : '未填写' }}</span>
                  <el-date-picker
                      v-else
                      v-model="form.studentSjby"
                      type="date"
                      value-format="YYYY-MM-DD"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentSjby">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="门类：">
                  <span v-if="!isEditing">{{ form.studentMl || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentMl"
                      :disabled="!fieldPermissions.studentMl" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="培养方式：">
                  <span v-if="!isEditing">{{ form.studentPyfs || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentPyfs"
                      :disabled="!fieldPermissions.studentPyfs" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="入学方式：">
                  <span v-if="!isEditing">{{ form.studentRxf || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentRxf"
                      :disabled="!fieldPermissions.studentRxf" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="培养方案ID：">
                  <span v-if="!isEditing">{{ form.trainingProgramId || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.trainingProgramId"
                      :disabled="!fieldPermissions.trainingProgramId" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="是否本校推免：">
                  <span v-if="!isEditing">{{ getDictLabel(sys_yes_no, form.studentSfbxtm) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentSfbxtm"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentSfbxtm">
                    <el-option
                        v-for="dict in sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 学习方式与计划子卡片 -->
        <el-card shadow="never" class="info-card">
          <template #header>
            <div class="card-header">
              <span>学习方式与计划</span>
            </div>
          </template>
          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="专项计划：">
                  <span v-if="!isEditing">{{ form.studentZxjh || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentZxjh"
                      :disabled="!fieldPermissions.studentZxjh" />
                </el-form-item>
              </el-col>
              <!-- 新增：专项计划2 -->
              <el-col :span="8">
                <el-form-item label="专项计划2：">
                  <span v-if="!isEditing">{{ form.studentZxjh2 || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentZxjh2"
                      :disabled="!fieldPermissions.studentZxjh2" />
                </el-form-item>
              </el-col>

              <el-col :span="8">
                <el-form-item label="就读方式：">
                  <span v-if="!isEditing">{{ form.studentJdfs || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentJdfs"
                      :disabled="!fieldPermissions.studentJdfs" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学习方式：">
                  <span v-if="!isEditing">{{ form.studentXxfs || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentXxfs"
                      :disabled="!fieldPermissions.studentXxfs" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="进修性质：">
                  <span v-if="!isEditing">{{ form.studentJxxz || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentJxxz"
                      :disabled="!fieldPermissions.studentJxxz" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否本校定向：">
                  <span v-if="!isEditing">{{ getDictLabel(sys_yes_no, form.studentSfbxdx) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentSfbxdx"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentSfbxdx">
                    <el-option
                        v-for="dict in sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否跨学科：">
                  <span v-if="!isEditing">{{ getDictLabel(sys_yes_no, form.studentSflkxk) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentSflkxk"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentSflkxk">
                    <el-option
                        v-for="dict in sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 学生类型与身份子卡片 -->
        <el-card shadow="never" class="info-card">
          <template #header>
            <div class="card-header">
              <span>学生类型与身份</span>
            </div>
          </template>
          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="是否在职生：">
                  <span v-if="!isEditing">{{ getDictLabel(sys_yes_no, form.studentSfzzs) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentSfzzs"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentSfzzs">
                    <el-option
                        v-for="dict in sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否留学生：">
                  <span v-if="!isEditing">{{ getDictLabel(sys_yes_no, form.studentSflxs) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentSflxs"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentSflxs">
                    <el-option
                        v-for="dict in sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="特殊学生类型：">
                  <span v-if="!isEditing">{{ form.studentTsxsx || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentTsxsx"
                      :disabled="!fieldPermissions.studentTsxsx" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学生分类：">
                  <span v-if="!isEditing">{{ form.studentXsfl || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentXsfl"
                      :disabled="!fieldPermissions.studentXsfl" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学位类型：">
                  <span v-if="!isEditing">{{ getDictLabel(culture_program_type, form.studentXwlx) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentXwlx"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentXwlx">
                    <el-option
                        v-for="dict in culture_program_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学位：">
                  <span v-if="!isEditing">{{ getDictLabel(degree, form.studentXw) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentXw"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentXw">
                    <el-option
                        v-for="dict in degree"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 在校状态卡片：下拉框加权限控制 -->
        <el-card shadow="never" class="info-card full-width-card">
          <template #header>
            <div class="card-header">
              <i-ep-data-line class="header-icon" />
              <span>在校状态</span>
            </div>
          </template>

          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="在校标识：">
                  <span v-if="!isEditing">{{ getDictLabel(school_identification, form.studentZxbs) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentZxbs"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentZxbs">
                    <el-option
                        v-for="dict in school_identification"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="注册状态：">
                  <span v-if="!isEditing">{{ getDictLabel(registration_status, form.studentZczt) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentZczt"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentZczt">
                    <el-option
                        v-for="dict in registration_status"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- 新增：在校生注册学号 -->
              <el-col :span="8">
                <el-form-item label="在校生注册学号：" label-width="140px">
                  <span v-if="!isEditing">{{ form.studentZxszcXh || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentZxszcXh"
                      :disabled="!fieldPermissions.studentZxszcXh" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学籍状态：">
                  <span v-if="!isEditing">{{ getDictLabel(schoolroll_status, form.studentXjzt) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentXjzt"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentXjzt">
                    <el-option
                        v-for="dict in schoolroll_status"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="报道状态：">
                  <span v-if="!isEditing">{{ getDictLabel(bdzt, form.studentStatus) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentStatus"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentStatus">
                    <el-option
                        v-for="dict in bdzt"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否破格：">
                  <span v-if="!isEditing">{{ getDictLabel(sys_yes_no, form.studentSfpg) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentSfpg"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentSfpg">
                    <el-option
                        v-for="dict in sys_yes_no"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="确认状态：">
                  <span v-if="!isEditing">{{ getDictLabel(confirmation_status, form.studentQrzt) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentQrzt"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentQrzt">
                    <el-option
                        v-for="dict in confirmation_status"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 入伍与退役信息卡片：日期选择器/输入框加权限控制 -->
        <el-card shadow="never" class="info-card full-width-card">
          <template #header>
            <div class="card-header">
              <i-ep-soldiers class="header-icon" />
              <span>入伍与退役信息</span>
            </div>
          </template>

          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="入伍时间：">
                  <span v-if="!isEditing">{{ form.studentRwsj ? form.studentRwsj.substring(0, 10) : '未填写' }}</span>
                  <el-date-picker
                      v-else
                      v-model="form.studentRwsj"
                      type="date"
                      value-format="YYYY-MM-DD"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentRwsj">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="退役时间：">
                  <span v-if="!isEditing">{{ form.studentTysj ? form.studentTysj.substring(0, 10) : '未填写' }}</span>
                  <el-date-picker
                      v-else
                      v-model="form.studentTysj"
                      type="date"
                      value-format="YYYY-MM-DD"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentTysj">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="批准入伍机关名称："  label-width="140px">
                  <span v-if="!isEditing">{{ form.studentPzrujgmc || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentPzrujgmc"
                      :disabled="!fieldPermissions.studentPzrujgmc" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="批准退役机关名称："  label-width="138px">
                  <span v-if="!isEditing">{{ form.studentPztyjgmc || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentPztyjgmc"
                      :disabled="!fieldPermissions.studentPztyjgmc" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="退出现役证编号："  label-width="140px">
                  <span v-if="!isEditing">{{ form.studentTcxyzbh || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentTcxyzbh"
                      :disabled="!fieldPermissions.studentTcxyzbh" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 入伍前高校信息卡片：输入框加权限控制 -->
        <el-card shadow="never" class="info-card full-width-card">
          <template #header>
            <div class="card-header">
              <i-ep-office-building class="header-icon" />
              <span>入伍前高校信息</span>
            </div>
          </template>

          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="入伍前所在高校名称："  label-width="160px">
                  <span v-if="!isEditing">{{ form.studentRwqszgxmc || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentRwqszgxmc"
                      :disabled="!fieldPermissions.studentRwqszgxmc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="入伍前所在高校学习形式："  label-width="180px">
                  <span v-if="!isEditing">{{ form.studentRwqszgxxxxs || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentRwqszgxxxxs"
                      :disabled="!fieldPermissions.studentRwqszgxxxxs" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="入伍前所在高校学习专业："  label-width="180px">
                  <span v-if="!isEditing">{{ form.studentRwqszgxxxzy || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentRwqszgxxxzy"
                      :disabled="!fieldPermissions.studentRwqszgxxxzy" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 毕业单位与档案信息卡片：输入框/下拉框加权限控制 -->
        <!-- 毕业单位与档案信息卡片：输入框/下拉框加权限控制（完整保留原始字段+新增字段） -->
        <el-card shadow="never" class="info-card full-width-card">
          <template #header>
            <div class="card-header">
              <i-ep-document class="header-icon" />
              <span>毕业单位与档案信息</span>
            </div>
          </template>

          <div class="info-group">
            <!-- 原有毕业单位基础字段（完整保留：毕业单位、毕业专业、毕业专业码） -->
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="毕业单位：">
                  <span v-if="!isEditing">{{ form.studentBydw || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentBydw"
                      :disabled="!fieldPermissions.studentBydw" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="毕业专业：">
                  <span v-if="!isEditing">{{ form.studentByzy || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentByzy"
                      :disabled="!fieldPermissions.studentByzy" />
                </el-form-item>
              </el-col>
              <!-- 原始保留：毕业专业码 -->
              <el-col :span="12">
                <el-form-item label="毕业专业码：">
                  <span v-if="!isEditing">{{ form.studentByzym || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentByzym"
                      :disabled="!fieldPermissions.studentByzym" />
                </el-form-item>
              </el-col>
            </el-row>

            <!-- 新增1：学士学位信息分组（4-9字段） -->
            <div class="sub-group-title">学士学位信息</div>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="获得学士学位单位码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBxwdywDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBxwdywDm" :disabled="!fieldPermissions.studentBxwdywDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获学士学位的单位名称：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBxwdywMc || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBxwdywMc" :disabled="!fieldPermissions.studentBxwdywMc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获学士学位专业代码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBxwzyDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBxwzyDm" :disabled="!fieldPermissions.studentBxwzyDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获学士学位专业名称：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBxwzyMc || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBxwzyMc" :disabled="!fieldPermissions.studentBxwzyMc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获学士学位年月：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBxwyxny || '未填写' }}</span>
                  <el-date-picker v-else
                                  v-model="form.studentBxwyxny"
                                  type="month"
                                  value-format="YYYY-MM"
                                  style="width: 100%;"
                                  :disabled="!fieldPermissions.studentBxwyxny" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="学士学位证书编号：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBxwzh || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBxwzh" :disabled="!fieldPermissions.studentBxwzh" />
                </el-form-item>
              </el-col>
            </el-row>

            <!-- 新增2：本科毕业信息分组（10-16字段） -->
            <div class="sub-group-title">本科毕业信息</div>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="本科毕业单位代码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBkbydwDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBkbydwDm" :disabled="!fieldPermissions.studentBkbydwDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="本科毕业单位名称：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBkbydwMc || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBkbydwMc" :disabled="!fieldPermissions.studentBkbydwMc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="本科毕业专业代码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBkbyzyDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBkbyzyDm" :disabled="!fieldPermissions.studentBkbyzyDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="本科毕业专业名称：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBkbyzyMc || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBkbyzyMc" :disabled="!fieldPermissions.studentBkbyzyMc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="本科毕业年月：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBkbyny || '未填写' }}</span>
                  <el-date-picker v-else
                                  v-model="form.studentBkbyny"
                                  type="month"
                                  value-format="YYYY-MM"
                                  style="width: 100%;"
                                  :disabled="!fieldPermissions.studentBkbyny" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="本科毕业证书编号：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentBkbyzh || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBkbyzh" :disabled="!fieldPermissions.studentBkbyzh" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="取得本科学历的学习形式：" label-width="180px">
                  <span v-if="!isEditing">{{ form.studentBkxxXsxs || '未填写' }}</span>
                  <el-input v-else v-model="form.studentBkxxXsxs" :disabled="!fieldPermissions.studentBkxxXsxs" />
                </el-form-item>
              </el-col>
            </el-row>

            <!-- 新增3：硕士学位信息分组（17-23字段） -->
            <div class="sub-group-title">硕士学位信息</div>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="获硕士学位的单位代码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSxwdywDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSxwdywDm" :disabled="!fieldPermissions.studentSxwdywDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获硕士学位的单位名称：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSxwdywMc || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSxwdywMc" :disabled="!fieldPermissions.studentSxwdywMc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获硕士学位专业代码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSxwzyDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSxwzyDm" :disabled="!fieldPermissions.studentSxwzyDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获硕士学位专业名称：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSxwzyMc || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSxwzyMc" :disabled="!fieldPermissions.studentSxwzyMc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获硕士学位年月：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSxwyxny || '未填写' }}</span>
                  <el-date-picker v-else
                                  v-model="form.studentSxwyxny"
                                  type="month"
                                  value-format="YYYY-MM"
                                  style="width: 100%;"
                                  :disabled="!fieldPermissions.studentSxwyxny" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="硕士学位证书编号：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSxwzh || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSxwzh" :disabled="!fieldPermissions.studentSxwzh" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="获硕士学位方式：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSxwfs || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSxwfs" :disabled="!fieldPermissions.studentSxwfs" />
                </el-form-item>
              </el-col>
            </el-row>

            <!-- 新增4：硕士毕业信息分组（24-29字段） -->
            <div class="sub-group-title">硕士毕业信息</div>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="硕士毕业单位代码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSbbydwDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSbbydwDm" :disabled="!fieldPermissions.studentSbbydwDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="硕士毕业单位名称：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSbbydwMc || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSbbydwMc" :disabled="!fieldPermissions.studentSbbydwMc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="硕士毕业专业代码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSbbyzyDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSbbyzyDm" :disabled="!fieldPermissions.studentSbbyzyDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="硕士毕业专业名称：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSbbyzyMc || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSbbyzyMc" :disabled="!fieldPermissions.studentSbbyzyMc" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="硕士毕业年月：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSbbyny || '未填写' }}</span>
                  <el-date-picker v-else
                                  v-model="form.studentSbbyny"
                                  type="month"
                                  value-format="YYYY-MM"
                                  style="width: 100%;"
                                  :disabled="!fieldPermissions.studentSbbyny" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="硕士毕业证书编号：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentSbbyzh || '未填写' }}</span>
                  <el-input v-else v-model="form.studentSbbyzh" :disabled="!fieldPermissions.studentSbbyzh" />
                </el-form-item>
              </el-col>
            </el-row>

            <!-- 新增5：最后学历学位信息分组（30-31字段） -->
            <div class="sub-group-title">最后学历学位信息</div>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="最后学位码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentZhxwDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentZhxwDm" :disabled="!fieldPermissions.studentZhxwDm" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="最后学历码：" label-width="160px">
                  <span v-if="!isEditing">{{ form.studentZhxlDm || '未填写' }}</span>
                  <el-input v-else v-model="form.studentZhxlDm" :disabled="!fieldPermissions.studentZhxlDm" />
                </el-form-item>
              </el-col>
            </el-row>

            <!-- 原有档案信息字段（完整保留：档案地址、档案邮政编码、档案状态、档案去向与内容） -->
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="档案地址：">
                  <span v-if="!isEditing">{{ form.studentDadz || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentDadz"
                      :disabled="!fieldPermissions.studentDadz" />
                </el-form-item>
              </el-col>
              <!-- 原始保留：档案邮政编码 -->
              <el-col :span="12">
                <el-form-item label="档案邮政编码：">
                  <span v-if="!isEditing">{{ form.studentDadzyzbm || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentDadzyzbm"
                      :disabled="!fieldPermissions.studentDadzyzbm" />
                </el-form-item>
              </el-col>
              <!-- 原始保留：档案状态 -->
              <el-col :span="12">
                <el-form-item label="档案状态："  class="long-text-form-item">
                  <span v-if="!isEditing">{{ getDictLabel(file_status, form.studentDazt) || '未填写' }}</span>
                  <el-select
                      v-else
                      v-model="form.studentDazt"
                      style="width: 100%;"
                      :disabled="!fieldPermissions.studentDazt">
                    <el-option v-for="item in file_status"
                               :key="item.value"
                               :label="item.label"
                               :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- 原始保留：档案去向与内容 -->
              <el-col :span="24">
                <el-form-item label="档案去向与内容：" class="long-text-form-item"  label-width="130px">
                  <div class="long-text-wrapper">
                    <span v-if="!isEditing" class="long-text-display">{{ form.studentDaqx || '未填写' }}</span>
                    <el-input
                        v-else
                        v-model="form.studentDaqx"
                        type="textarea"
                        :rows="3"
                        resize="vertical"
                        :disabled="!fieldPermissions.studentDaqx">
                    </el-input>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 定向与录取信息卡片：输入框加权限控制 -->
        <el-card shadow="never" class="info-card full-width-card">
          <template #header>
            <div class="card-header">
              <i-ep-position class="header-icon" />
              <span>定向与录取信息</span>
            </div>
          </template>

          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="定向就业单位：">
                  <span v-if="!isEditing">{{ form.studentDxjydw || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentDxjydw"
                      :disabled="!fieldPermissions.studentDxjydw" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="定向就业单位码："  label-width="130px">
                  <span v-if="!isEditing">{{ form.studentDxjydwm || '未填写'  }}</span>
                  <el-input
                      v-else
                      v-model="form.studentDxjydwm"
                      :disabled="!fieldPermissions.studentDxjydwm" />
                </el-form-item>
              </el-col>
              <!-- 新增：定向就业单位所在地码 -->
              <el-col :span="12">
                <el-form-item label="定向就业单位所在地码："  label-width="160px">
                  <span v-if="!isEditing">{{ form.studentDxjydwSdm || '未填写'  }}</span>
                  <el-input
                      v-else
                      v-model="form.studentDxjydwSdm"
                      :disabled="!fieldPermissions.studentDxjydwSdm" />
                </el-form-item>
              </el-col>

              <el-col :span="12">
                <el-form-item label="录取培养单位：">
                  <span v-if="!isEditing">{{ form.studentLqpydw || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentLqpydw"
                      :disabled="!fieldPermissions.studentLqpydw" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="录取培养单位码："  label-width="130px">
                  <span v-if="!isEditing">{{ form.studentLqpydwm || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentLqpydwm"
                      :disabled="!fieldPermissions.studentLqpydwm" />
                </el-form-item>
              </el-col>
              <!-- 新增：招生单位所在省市码 -->
              <el-col :span="12">
                <el-form-item label="招生单位所在省市码："  label-width="160px">
                  <span v-if="!isEditing">{{ form.studentZsdwSssm || '未填写'  }}</span>
                  <el-input
                      v-else
                      v-model="form.studentZsdwSssm"
                      :disabled="!fieldPermissions.studentZsdwSssm" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>

        <!-- 毕业预答辩信息卡片 -->
        <el-card shadow="never" class="info-card full-width-card">
          <template #header>
            <div class="card-header">
              <i-ep-calendar class="header-icon" />
              <span>毕业预答辩信息</span>
            </div>
          </template>

          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="答辩时间：">
                  <span v-if="!isEditing">{{ form.studentDbsj ? form.studentDbsj.substring(0, 10) : '未填写' }}</span>
                  <el-date-picker v-else
                                  v-model="form.studentDbsj"
                                  type="date"
                                  value-format="YYYY-MM-DD"
                                  style="width: 100%;"
                                  :disabled="!fieldPermissions.studentDbsj">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="毕业证号：">
                  <span v-if="!isEditing">{{ form.studentByzh || '未填写' }}</span>
                  <el-input v-else v-model="form.studentByzh" :disabled="!fieldPermissions.studentByzh"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="学位证号：">
                  <span v-if="!isEditing">{{ form.studentXwzh || '未填写' }}</span>
                  <el-input v-else v-model="form.studentXwzh" :disabled="!fieldPermissions.studentXwzh"/>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="奖惩信息：">
                  <span v-if="!isEditing">{{ form.studentJcxx || '未填写' }}</span>
                  <el-input v-else v-model="form.studentJcxx" type="textarea" :disabled="!fieldPermissions.studentJcxx"/>
                </el-form-item>
              </el-col>

            </el-row>
          </div>
        </el-card>

        <!-- 其他教育信息卡片 -->
        <el-card shadow="never" class="info-card full-width-card">
          <template #header>
            <div class="card-header">
              <i-ep-more class="header-icon" />
              <span>其他教育信息</span>
            </div>
          </template>

          <div class="info-group">
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="考试方式：">
                  <span v-if="!isEditing">{{ getDictLabel(method_examination,form.ksfs) }}</span>
                  <!-- 权限控制：考试方式下拉框 -->
                  <el-select
                      v-else
                      v-model="form.ksfs"
                      placeholder="请选择"
                      :disabled="!fieldPermissions.ksfs">
                    <el-option v-for="item in method_examination"
                               :key="item.value"
                               :label="item.label"
                               :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- 新增33：考生来源码 -->
              <el-col :span="12">
                <el-form-item label="考生来源码：" label-width="120px">
                  <span v-if="!isEditing">{{ form.studentKslyDm || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentKslyDm"
                      :disabled="!fieldPermissions.studentKslyDm" />
                </el-form-item>
              </el-col>
              <!-- 新增34：考试方式码 -->
              <el-col :span="12">
                <el-form-item label="考试方式码：" label-width="120px">
                  <span v-if="!isEditing">{{ form.studentKsfsDm || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentKsfsDm"
                      :disabled="!fieldPermissions.studentKsfsDm" />
                </el-form-item>
              </el-col>
              <!-- 新增35：录取类别码 -->
              <el-col :span="12">
                <el-form-item label="录取类别码：" label-width="120px">
                  <span v-if="!isEditing">{{ form.studentLqlbDm || '未填写' }}</span>
                  <el-input
                      v-else
                      v-model="form.studentLqlbDm"
                      :disabled="!fieldPermissions.studentLqlbDm" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注：">
                  <span v-if="!isEditing">{{ form.beizhu || '未填写' }}</span>
                  <!-- 权限控制：备注文本域 -->
                  <el-input
                      v-else
                      v-model="form.beizhu"
                      type="textarea"
                      :disabled="!fieldPermissions.beizhu" />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-card>


      </el-card>
      <!-- 其他信息卡片 -->
      <el-card shadow="never" class="info-card full-width-card">
        <template #header>
          <div class="card-header">
            <i-ep-info-filled class="header-icon" />
            <span>其他信息</span>
          </div>
        </template>

        <div class="info-group">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="港澳台侨：">
                <span v-if="!isEditing">{{ getDictLabel(originpadict, form.gangaotaiqiao) || '未填写' }}</span>
                <!-- 权限控制：港澳台侨下拉框 -->
                <el-select
                    v-else
                    v-model="form.gangaotaiqiao"
                    style="width: 100%;"
                    :disabled="!fieldPermissions.gangaotaiqiao">
                  <el-option
                      v-for="dict in originpadict"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="婚姻状况：">
                <span v-if="!isEditing">{{ getDictLabel(marital_status, form.studentMarr) || '未填写' }}</span>
                <!-- 权限控制：婚姻状况下拉框 -->
                <el-select
                    v-else
                    v-model="form.studentMarr"
                    style="width: 100%;"
                    :disabled="!fieldPermissions.studentMarr">
                  <el-option
                      v-for="dict in marital_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="健康状况：">
                <span v-if="!isEditing">{{ getDictLabel(health_status, form.studentHe) || '未填写' }}</span>
                <!-- 权限控制：健康状况下拉框 -->
                <el-select
                    v-else
                    v-model="form.studentHe"
                    style="width: 100%;"
                    :disabled="!fieldPermissions.studentHe">
                  <el-option
                      v-for="dict in health_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="问题学生类别：">
                <span v-if="!isEditing">{{ form.studentQues || '未填写' }}</span>
                <!-- 权限控制：问题学生类别输入框 -->
                <el-input
                    v-else
                    v-model="form.studentQues"
                    :disabled="!fieldPermissions.studentQues" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="病史：">
                <span v-if="!isEditing">{{ form.studentBs || '未填写' }}</span>
                <!-- 权限控制：病史文本域 -->
                <el-input
                    v-else
                    v-model="form.studentBs"
                    type="textarea"
                    :disabled="!fieldPermissions.studentBs" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="事由：">
                <span v-if="!isEditing">{{ form.studentSy || '未填写' }}</span>
                <!-- 权限控制：事由文本域 -->
                <el-input
                    v-else
                    v-model="form.studentSy"
                    type="textarea"
                    :disabled="!fieldPermissions.studentSy" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-card>
    </el-form>
  </div>
</template>

<script setup>
import useUserStore from '@/store/modules/user';
import { ref, reactive, onMounted, computed, getCurrentInstance } from 'vue'
import { getMajorByCollegeId, listMajor } from "@/api/major/major.js"
import { listCollege } from "@/api/college/college.js"
import { listTeacher } from "@/api/teacher/teacher.js"
// import { getStudentManger, updateStudentManger } from "@/api/student/studentManger"
import { listNation } from "@/api/dictionaries/nation.js"
import { listPoliticalstatus } from "@/api/dictionaries/politicalstatus.js"
import { loadAllParams } from "@/api/page.js";
import {listGertificatetype} from "@/api/dictionaries/gertificatetype.js";
import {regionData} from "element-china-area-data";
import { debounce } from 'lodash';
import { pinyin } from 'pinyin-pro';
import ImageUpload from "@/components/ImageUpload/index.vue";
// 导入新增的API
import { getStudentFieldPermissions,getStudentManger, updateStudentManger ,getStudentInfoByStudentId,getStudentInfoByStudentXh} from "@/api/student/studentManger"
// 新增：字段权限映射（key=字段编码，value=是否可修改）
// 改造后（动态填充）：
// key=前端form字段名（驼峰），value=是否可修改（is_change=1→true）
const fieldPermissions = reactive({});

// 新增：下划线命名转驼峰命名（适配数据库field_code与前端form字段）
const underlineToCamel = (str) => {
  if (!str) return '';
  return str.replace(/_([a-z])/g, (match, letter) => letter.toUpperCase());
};
// 获取当前实例
const { proxy } = getCurrentInstance()
const { originpadict,grade,campus_type,semester,xuezhi,bdzt,marital_status,health_status,culture_program_type,sys_yes_no,sys_user_sex,degree,school_identification,registration_status,schoolroll_status,file_status,confirmation_status,test_format,method_examination} =
    proxy.useDict('originpadict' , 'grade', 'campus_type','semester', 'xuezhi', 'bdzt', 'marital_status','health_status','culture_program_type','sys_yes_no','sys_user_sex','degree','school_identification','registration_status','schoolroll_status','file_status','confirmation_status','test_format','method_examination');

// 编辑状态
const isEditing = ref(false)
const loading = ref(false)
// 原始数据备份
const originalForm = ref({})

// 数据引用
const form = reactive({
  id: null,
  studentGphoto: null,
  studentPhoto: null,
  studentId: null,
  studentName: null,
  namePy: null,
  studentNames: null,
  studentSex: null,
  birthday: null,
  studentNation: null,
  studentPa: null,
  studentTjp: null,
  studentCtype: null,
  studentCnum: null,
  studentRe: null,
  studentRegion: null,
  studentJiguan: null,
  studentBire: null,
  studentStre: null,
  studentHk: null,
  studentHkxxdz: null,
  gangaotaiqiao: null,
  studentMarr: null,
  studentHe: null,
  studentBs: null,
  studentYhkh: null,
  studentYhkname: null,
  studentTrains: null,
  studentTraine: null,
  studentQues: null,
  studentShuji: null,
  studentSjnum: null,
  studentFdy: null,
  studentFdynum: null,
  studentSy: null,
  studentYx: null,
  studentZy: null,
  studentYjfx: null,
  studentYjfxm: null,
  studentPycc: null,
  studentLb: null,
  studentNj: null,
  studentXq: null,
  studentDs: null,
  studentDs2: null,
  studentDsbh: null,
  studentDs2bh: null,
  studentBj: null,
  studentXz: null,
  studentRxjj: null,
  studentRxny: null,
  studentYjby: null,
  studentSjby: null,
  studentMl: null,
  studentPyfs: null,
  studentRxf: null,
  studentZxjh: null,
  studentJdfs: null,
  studentXxfs: null,
  studentJxxz: null,
  studentSfbxtm: null,
  studentSfbxdx: null,
  studentSflkxk: null,
  studentSfzzs: null,
  studentSflxs: null,
  studentTsxsx: null,
  studentXsfl: null,
  studentXwlx: null,
  studentXw: null,
  studentZxbs: null,
  studentZczt: null,
  studentXjzt: null,
  studentDazt: null,
  studentSfpg: null,
  studentDaqx: null,
  studentQrzt: null,
  studentBydw: null,
  studentByzy: null,
  studentByzym: null,
  studentDadz: null,
  studentDadzyzbm: null,
  studentDbsj: null,
  studentByzh: null,
  studentXwzh: null,
  studentJcxx: null,
  ksfs: null,
  beizhu: null,
  studentDxjydw: null,
  studentDxjydwm: null,
  studentLqpydw: null,
  studentLqpydwm: null,
  studentSjh: null,
  studentRwsj: null,
  studentTysj: null,
  studentPzrujgmc: null,
  studentPztyjgmc: null,
  studentTcxyzbh: null,
  studentRwqszgxmc: null,
  studentRwqszgxxxxs: null,
  studentRwqszgxxxzy: null,
  studentStatus: null,
  trainingProgramId: null,
  // 新增36个字段开始
  studentDxjydwSdm: null,    // 1.定向就业单位所在地码
  studentZxjh2: null,        // 2.专项计划2
  studentZsdwSssm: null,     // 3.招生单位所在省市码
  studentBxwdywDm: null,     // 4.获得学士学位单位码
  studentBxwdywMc: null,     // 5.获学士学位的单位名称
  studentBxwzyDm: null,      // 6.获学士学位专业代码
  studentBxwzyMc: null,      // 7.获学士学位专业名称
  studentBxwyxny: null,      // 8.获学士学位年月
  studentBxwzh: null,        // 9.学士学位证书编号
  studentBkbydwDm: null,     // 10.本科毕业单位代码
  studentBkbydwMc: null,     // 11.本科毕业单位名称
  studentBkbyzyDm: null,     // 12.本科毕业专业代码
  studentBkbyzyMc: null,     // 13.本科毕业专业名称
  studentBkbyny: null,       // 14.本科毕业年月
  studentBkbyzh: null,       // 15.本科毕业证书编号
  studentBkxxXsxs: null,     // 16.取得本科学历的学习形式
  studentSxwdywDm: null,     // 17.获硕士学位的单位代码
  studentSxwdywMc: null,     // 18.获硕士学位的单位名称
  studentSxwzyDm: null,      // 19.获硕士学位专业代码
  studentSxwzyMc: null,      // 20.获硕士学位专业名称
  studentSxwyxny: null,      // 21.获硕士学位年月
  studentSxwzh: null,        // 22.硕士学位证书编号
  studentSxwfs: null,        // 23.获硕士学位方式
  studentSbbydwDm: null,     // 24.硕士毕业单位代码
  studentSbbydwMc: null,     // 25.硕士毕业单位名称
  studentSbbyzyDm: null,     // 26.硕士毕业专业代码
  studentSbbyzyMc: null,     // 27.硕士毕业专业名称
  studentSbbyny: null,       // 28.硕士毕业年月
  studentSbbyzh: null,       // 29.硕士毕业证书编号
  studentZhxwDm: null,       // 30.最后学位码
  studentZhxlDm: null,       // 31.最后学历码
  studentZxszcXh: null,      // 32.在校生注册学号
  studentKslyDm: null,       // 33.考生来源码
  studentKsfsDm: null,       // 34.考试方式码
  studentLqlbDm: null,       // 35.录取类别码
  studentXyjrDm: null        // 36.现役军人码
  // 新增36个字段结束
})

const data = reactive({
  // 地区选择器选项
  options: regionData,
  selectedOptions: [],
  selectedJiguan: [],
  selectedBire: [],
  selectedStre: [],
  selectedHk: []
})

// 使用 toRefs 确保响应性
const { options, selectedOptions, selectedJiguan, selectedBire, selectedStre, selectedHk } = data;

// 列表数据
const originnationlist = ref([])
const originpaList = ref([])
const yxList = ref([])
const zyList = ref([])
const zjlxList = ref([])
const teacherList = ref([])

// 地区文本显示
const regionText = computed(() => {
  if (!form.studentRegion) return '';
  return formatRegion(form.studentRegion);
});

const jiguanText = computed(() => {
  if (!form.studentJiguan) return '';
  return formatRegion(form.studentJiguan);
});

const bireText = computed(() => {
  if (!form.studentBire) return '';
  return formatRegion(form.studentBire);
});

const streText = computed(() => {
  if (!form.studentStre) return '';
  return formatRegion(form.studentStre);
});

const hkText = computed(() => {
  if (!form.studentHk) return '';
  return formatRegion(form.studentHk);
});

// 获取完整的图片URL
function getImageUrl(path) {
  if (!path) return '';

  // 如果是完整URL，直接返回
  if (path.startsWith('http://') || path.startsWith('https://')) {
    return path;
  }

  // 获取基础API路径
  const baseUrl = import.meta.env.VITE_APP_BASE_API || '';

  // 处理相对路径
  if (path.startsWith('/')) {
    return baseUrl + path;
  } else {
    return baseUrl + '/' + path;
  }
}

// 获取字典标签
function getDictLabel(dictList, value) {
  if (!value || !dictList) return '';
  const dict = dictList.find(item => item.value === value);
  return dict ? dict.label : '';
}

// 获取民族标签
function getNationLabel(value) {
  if (!value) return '';
  const nation = originnationlist.value.find(item => item.nadictValue === value);
  return nation ? nation.nadictLabel : '';
}

// 获取政治面貌标签
function getPoliticalLabel(value) {
  if (!value) return '';
  const political = originpaList.value.find(item => item.politicalValue === value);
  return political ? political.politicalLabel : '';
}

// 获取证件类型标签
function getZjlxLabel(value) {
  if (!value) return '';
  const zjlx = zjlxList.value.find(item => item.cardtValue === value);
  return zjlx ? zjlx.cardtLabel : '';
}

// 获取院系名称
function getCollegeName(code) {
  if (!code) return '';
  const college = yxList.value.find(item => item.collegeCode === code);
  return college ? college.collegeName : '';
}

// 获取专业名称
function getMajorName(code) {
  if (!code) return '';
  const major = zyList.value.find(item => item.majorCode === code);
  return major ? major.majorName : '';
}

// 获取导师名称
function getTeacherName(code) {
  if (!code) return '';
  const teacher = teacherList.value.find(item => item.teacherCode === code);
  return teacher ? teacher.name : '';
}

// 格式化地区显示
function formatRegion(code) {
  if (!code) return '';

  for (const province of regionData) {
    if (province.value === code) {
      return province.label;
    }

    if (province.children) {
      for (const city of province.children) {
        if (city.value === code) {
          return `${province.label}/${city.label}`;
        }

        if (city.children) {
          for (const area of city.children) {
            if (area.value === code) {
              return `${province.label}/${city.label}/${area.label}`;
            }
          }
        }
      }
    }
  }

  return code;
}

// 院系变更时触发
function handleCollegeChange(collegeId) {
  if (!collegeId) return;
  // 调用API查询该院系下的专业
  getMajorByCollegeId(collegeId).then(response => {
    zyList.value = response.rows;
    // 可选：自动清空之前的专业选择（如果需要）
    form.studentZy = null;
  });
}

// 创建防抖函数
const debouncedGetNamePy = debounce(function() {
  if (form.studentName) {
    const namePy = pinyin(form.studentName, { style: pinyin.STYLE_FIRST_LETTER, toneType: "none", type: "string"});
    form.namePy = namePy;
  }
}, 500);

// 根据输入的姓名生成名字拼音
function getNamePy() {
  debouncedGetNamePy();
}

// 根据身份证判断性别
function getSex() {
  if (form.studentCnum && form.studentCnum.length >= 17) {
    const sex = form.studentCnum.at(16) % 2 === 0 ? '2' : '1'; // 假设1为男，2为女
    if (form.studentSex !== sex) {
      form.studentSex = sex;
      proxy.$modal.msgSuccess('已根据身份证修改学生性别');
    }
  }
}

// 地区选择器回调
function handleChange() {
  form.studentRegion = selectedOptions.length > 0 ? selectedOptions[selectedOptions.length - 1] : null;
}

function handleChangeJiguan() {
  form.studentJiguan = selectedJiguan.length > 0 ? selectedJiguan[selectedJiguan.length - 1] : null;
}

function handleChangeBire() {
  form.studentBire = selectedBire.length > 0 ? selectedBire[selectedBire.length - 1] : null;
}

function handleChangeStre() {
  form.studentStre = selectedStre.length > 0 ? selectedStre[selectedStre.length - 1] : null;
}

function handleChangeHk() {
  form.studentHk = selectedHk.length > 0 ? selectedHk[selectedHk.length - 1] : null;
}

// 加载学生详情
const loadStudentDetail = async (id) => {
  loading.value = true;
  try {
    const res = await getStudentInfoByStudentXh(id);
    Object.assign(form, res.data);

    // 设置地区选择器的值
    if (form.studentRegion) {
      selectedOptions.splice(0, selectedOptions.length, ...findRegionPath(form.studentRegion));
    }
    if (form.studentJiguan) {
      selectedJiguan.splice(0, selectedJiguan.length, ...findRegionPath(form.studentJiguan));
    }
    if (form.studentBire) {
      selectedBire.splice(0, selectedBire.length, ...findRegionPath(form.studentBire));
    }
    if (form.studentStre) {
      selectedStre.splice(0, selectedStre.length, ...findRegionPath(form.studentStre));
    }
    if (form.studentHk) {
      selectedHk.splice(0, selectedHk.length, ...findRegionPath(form.studentHk));
    }

    // 加载院系对应的专业
    if (form.studentYx) {
      const majorRes = await getMajorByCollegeId(form.studentYx);
      zyList.value = majorRes.rows;
    }
  } catch (error) {
    console.error('加载学生信息失败:', error);
    proxy.$modal.msgError('加载学生信息失败');
  } finally {
    loading.value = false;
  }
}

// 查找地区路径的函数
function findRegionPath(code) {
  if (!code) return [];

  for (const province of regionData) {
    if (province.value === code) {
      return [province.value];
    }

    if (province.children) {
      for (const city of province.children) {
        if (city.value === code) {
          return [province.value, city.value];
        }

        if (city.children) {
          for (const area of city.children) {
            if (area.value === code) {
              return [province.value, city.value, area.value];
            }
          }
        }
      }
    }
  }

  return [code];
}

// 加载民族列表
const loadNations = async () => {
  try {
    const res = await listNation(loadAllParams);
    originnationlist.value = res.rows;
  } catch (error) {
    console.error('加载民族列表失败:', error);
  }
}

// 加载证件类型列表
const loadZjlxList = async () => {
  try {
    const res = await listGertificatetype(loadAllParams);
    zjlxList.value = res.rows;
  } catch (error) {
    console.error('加载证件类型列表失败:', error);
  }
}

// 加载政治面貌列表
const loadPoliticalStatus = async () => {
  try {
    const res = await listPoliticalstatus(loadAllParams);
    originpaList.value = res.rows;
  } catch (error) {
    console.error('加载政治面貌列表失败:', error);
  }
}

// 加载学院列表
const loadColleges = async () => {
  try {
    const res = await listCollege(loadAllParams);
    yxList.value = res.rows;
  } catch (error) {
    console.error('加载学院列表失败:', error);
  }
}

// 加载专业列表
const loadMajors = async () => {
  try {
    const res = await listMajor(loadAllParams);
  } catch (error) {
    console.error('加载专业列表失败:', error);
  }
}

// 加载教师列表
const loadTeachers = async () => {
  try {
    const res = await listTeacher(loadAllParams);
    teacherList.value = res.rows;
  } catch (error) {
    console.error('加载教师列表失败:', error);
  }
}

// 修改 handleEdit 函数
const handleEdit = () => {
  // 进入编辑模式前备份原始数据
  originalForm.value = JSON.parse(JSON.stringify(form));
  isEditing.value = true;
  proxy.$modal.msgInfo('进入编辑模式');
}

// 取消编辑
const cancelEdit = () => {
  // 恢复原始数据
  Object.assign(form, originalForm.value);
  isEditing.value = false;
  proxy.$modal.msgInfo('已取消编辑');
}

const handlePrint = () => {
  proxy.$modal.msgInfo('打印功能准备中');
  window.print();
}

const handleExport = () => {
  proxy.$modal.msgInfo('导出PDF功能准备中');
}

// 修改保存编辑函数
// 新增：提交前拦截（防止前端绕过禁用修改）
// 改造后（动态拦截所有不可修改字段）：
const saveEdit = () => {
  // 1. 找到所有“不可修改但被变更”的字段
  const changedDisabledFields = Object.keys(fieldPermissions).filter(fieldName => {
    // 条件：字段不可修改 + 当前值≠原始值
    return !fieldPermissions[fieldName] && form[fieldName] !== originalForm.value[fieldName];
  });

  // 2. 若有变更，提示用户（用中文字段名提升体验）
  if (changedDisabledFields.length > 0) {
    // 字段名映射：前端字段→中文提示（可根据数据库field_name补充完整）
    const fieldNameMap = {
      studentId: '学号',
      studentName: '姓名',
      studentSex: '性别',
      birthday: '出生日期',
      studentNation: '民族',
      studentPa: '政治面貌',
      // ...其他所有字段的中文映射（对应数据库field_name）
    };
    // 转换为中文提示（如“学号、姓名不可修改”）
    const fieldLabels = changedDisabledFields.map(field => fieldNameMap[field] || field).join('、');
    proxy.$modal.msgError(`${fieldLabels}不可修改，请恢复原始值！`);
    return;
  }

  // 3. 原有表单校验逻辑（不变）
  proxy.$refs["studentMangerRef"].validate(valid => {
    if (valid) {
      updateStudentManger(form).then(response => {
        proxy.$modal.msgSuccess("修改成功");
        isEditing.value = false;
        loadStudentDetail(form.id);
      }).catch(error => {
        proxy.$modal.msgError("修改失败: " + error.message);
      });
    }
  });
}

// 新增：加载字段权限配置
const loadFieldPermissions = async () => {
  try {
    const res = await getStudentFieldPermissions()
    // 1. 打印后端返回的原始数据（确认格式）
    console.log('后端返回的权限数据（对象格式）：', res.data);

    const permissionObj = res.data || {}; // 现在是对象格式，而非数组
    console.log('处理后的权限对象：', permissionObj);

    // 清空原有权限
    Object.keys(fieldPermissions).forEach(key => delete fieldPermissions[key]);
    console.log('清空后权限对象：', fieldPermissions);

    // 动态填充权限（遍历对象的键值对，而非数组）
    // 键：数据库字段名（如beizhu、student_marr）
    // 值：is_change（1=可修改，0=不可修改）
    Object.keys(permissionObj).forEach(dbField => {
      const isChange = permissionObj[dbField]; // 获取is_change值
      const frontField = underlineToCamel(dbField); // 转换为前端驼峰字段（如student_marr→studentMarr）
      const isEditable = isChange === 1; // 1→可修改

      // 打印单个字段的转换关系（用于调试）
      console.log(`数据库字段[${dbField}] → 前端字段[${frontField}]，可修改：${isEditable}`);

      if (frontField) {
        fieldPermissions[frontField] = isEditable;
      }
    });

    // 处理未返回的字段（默认不可修改）
    Object.keys(form).forEach(frontField => {
      if (fieldPermissions[frontField] === undefined) {
        fieldPermissions[frontField] = false;
        console.log(`未配置权限的字段[${frontField}]，默认设为不可修改`);
      }
    });

    // 打印最终权限对象
    console.log('最终权限对象（控制字段是否可修改）：', fieldPermissions);

  } catch (error) {
    console.error('加载字段权限失败:', error);
    proxy.$modal.msgError('加载权限配置失败');
  }
}
const userStore = useUserStore();

// 组件挂载时加载数据
onMounted(() => {
  // 假设从路由参数中获取学生ID
// 获取用户名（userName，登录账号）
  const username = userStore.name;
  console.log('用户名（userName）：', username);
  console.log('用户信息（userStore）：', userStore);
  console.log('用户信息（userStore.roles）：', userStore.roles);
// 获取用户昵称（nickName，显示名称）
  const nickName = userStore.nickName;
  const studentId = username;

  // 加载数据
  loadStudentDetail(studentId);
  loadNations();
  loadPoliticalStatus();
  loadColleges();
  loadMajors();
  loadZjlxList();
  loadTeachers();
  // 新增：加载字段权限
  loadFieldPermissions();
})




</script>

<style scoped>
.student-profile-container {
  padding: 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4edf9 100%);
  min-height: 100vh;
}

.profile-header {
  margin-bottom: 20px;
  padding: 15px 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.page-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  color: #000000;
}

.action-buttons {
  display: flex;
  gap: 12px;
}

.profile-content {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.info-card {
  border-radius: 12px;
  border: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  background: white;
  margin-bottom: 20px;
}

.full-width-card {
  width: 100%;
}

.card-header {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
}

.header-icon {
  margin-right: 10px;
  font-size: 20px;
  color: #1890ff;
}

.info-group {
  padding: 15px 0;
}

.info-group .el-row {
  display: flex;
  align-items: center;
}

.info-group .el-form-item {
  margin-bottom: 18px;
}

.info-group :deep(.el-form-item__label) {
  font-weight: 500;
  color: #34495e;
}

.photo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.photo-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.photo-label {
  font-weight: 500;
  color: #34495e;
  margin-bottom: 10px;
}

.photo-preview {
  width: 120px;
  height: 150px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  margin-bottom: 10px;
  background-color: #f5f7fa;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.photo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-slot {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  color: #909399;
  font-size: 14px;
}

.image-slot i {
  font-size: 24px;
  margin-bottom: 5px;
}

.basic-info-section {
  padding: 0 15px;
}

:deep(.el-card__header) {
  padding: 18px 20px;
  border-bottom: 1px solid #ecf0f1;
  background-color: #f8f9fa;
}

@media (max-width: 1200px) {
  .profile-content {
    flex-direction: column;
  }

  .header-content {
    flex-direction: column;
    gap: 15px;
    align-items: flex-start;
  }

  .action-buttons {
    width: 100%;
    justify-content: flex-end;
  }
}
.upload-tips {
  font-size: 12px;
  color: #909399;
  margin-top: 5px;
  text-align: center;
}


/* 原有样式不变，可新增禁用输入框样式（可选） */
:deep(.el-input.is-disabled .el-input__inner) {
  background-color: #f5f7fa;
  color: #666;
  cursor: not-allowed;
}
/* 新增子分组标题样式，区分不同学历模块 */
.sub-group-title {
  font-size: 16px;
  font-weight: 600;
  color: #1890ff;
  margin: 20px 0 10px;
  padding-left: 5px;
  border-left: 3px solid #1890ff;
}

/* 保留原始代码中的样式（未修改） */
.info-group {
  padding: 15px 0;
}
.info-group .el-row {
  display: flex;
  align-items: center;
}
.info-group .el-form-item {
  margin-bottom: 18px;
}
.info-group :deep(.el-form-item__label) {
  font-weight: 500;
  color: #34495e;
}
.long-text-form-item :deep(.el-form-item__content) {
  width: calc(100% - 130px);
}
.long-text-wrapper {
  width: 100%;
}
.long-text-display {
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}
</style>
